<template>
	<view>
		<view @touchmove.stop.prevent :class="lecturer ? 'shade' : ''"></view>
		<view class="video">
			<view :class="trysee ? 'shade' : ''" @touchmove.stop.prevent></view>
			<view class="back" @click="back"><image src="http://one-huoke.oss-cn-hangzhou.aliyuncs.com/c6227202209231808366793.png" mode=""></image></view>
			<video
				@timeupdate="monitorDuration"
				id="myVideo"
				style="width: 100vw;height: 500rpx;"
				direction="90"
				:enable-play-gesture="true"
				:show-center-play-btn="true"
				:show-loading="true"
				:vslide-gesture-in-fullscreen="true"
				:controls="true"
				:src="shipinLink"
				:title="shipintitle"
			></video>

			<view class="playbtn1" @click="playy" v-if="palybtn"><image src="https://www.szzn.group/uploads/20221114/532b0e627bb3e4e1709e3e21f6df5256.png" mode=""></image></view>

			<view class="playbtn" v-if="fengmian"><image :src="shipinFengmian" mode=""></image></view>

			<view class="trysee" v-if="trysee">
				<view class="">试看{{ trytime }}秒，观看完整视频请购买教程</view>
			</view>
		</view>
		<view class="content">
			<view class="zz-title">{{ detailData.special.title }}</view>
			<view class="">
				<view v-for="(item, index) in detailData.special.label" :key="index" class="">{{ item }}</view>
			</view>

			<view class=""></view>

			<view class="">
				<view class="zz-price">
					<text>￥</text>
					{{ detailData.special.money }}
				</view>
				<view class="">{{ recordCoujnt }}人购买</view>
			</view>

			<view class=""></view>

			<view class="">
				<view class="share">
					<image src="http://www.szzn.group/uploads/20221107/be40749edd900afaa50a26715437d86d.png" mode=""></image>
					<view class="">分享</view>
					<button open-type="share">123</button>
				</view>
				<view class="cllooect" @click="Cllooect(detailData.special.id, detailData.special.collect)">
					<image src="http://www.szzn.group/uploads/20221108/8815a55650350973049669b20ca6b012.png" mode=""></image>
					<view class="">{{ detailData.special.collect ? '已收藏' : '收藏' }}</view>
				</view>

				<view class="title-list">
					<view :class="active == 1 ? 'active-style' : ''" @click="activeC(1)">课程介绍</view>
					<view :class="active == 2 ? 'active-style' : ''" @click="activeC(2)">课程目录</view>
				</view>

				<view v-show="active == 1">
					<view class="courseone">
						<view class="acquisition">你将获得</view>
						<view class="jianjie">· {{ detailData.special.abstract }}</view>
					</view>

					<view class="courseone"><view class="">教学服务</view></view>
					<view class="border">
						<view class="" v-for="(i, index) in 4" :key="index">
							<view class="border-flex">
								<image src="http://www.szzn.group/uploads/20221108/154e027703ea7f5919ae8886a514fdd3.png" mode=""></image>
								<view class="border-title">1v1专属答疑服务强无敌群</view>
							</view>
						</view>
					</view>

					<view class="courseone " @click="lecturerPopul">
						<view class="">讲师介绍</view>
						<view class="lecturer">
							<view class=""><image :src="detailData.teacher.lecturer_head" mode=""></image></view>
							<view class="">
								<view class="">老师：{{ detailData.teacher.lecturer_name }}</view>
								<view class="" v-for="i in detailData.teacher.label" :key="i.id">
									<view class="">{{ i }}</view>
								</view>
							</view>
						</view>
					</view>

					<view class="detail">
						<view class="cutoffrule"></view>
						<view class="coursedetail">课程详情</view>
						<view class="cutoffrule"></view>
					</view>

					<view class="textdetail">
						<mp-html :content="detailData.special.content" />
					</view>
				</view>

				<view v-show="active == 2">
					<view class="coursecatalogue" v-for="(i, inx) in courseList" :key="i.id">
						<view class="">
							<view class=""><image src="http://one-huoke.oss-cn-hangzhou.aliyuncs.com/38f6a202209231738233121.png" mode=""></image></view>
							<view class="">
								<view class="">
									<view class="">{{ inx + 1 }}.{{ i.title }}</view>
									<!-- <view class="">04:10 | 100人已学</view> -->
								</view>
								<view class="" @click="videoPay(i.id, i.try_time, detailData.isPay)">
									{{ detailData.isPay ? '观看' : i.is_try == 0 ? '购买' : i.try_time == 0 ? '购买' : '试看' }}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="fooder">
			<view class="">
				<view class="kefu">
					<image src="http://one-huoke.oss-cn-hangzhou.aliyuncs.com/8744c202209231920019646.png" mode=""></image>
					<view class="">客服</view>
					<button open-type="contact">客服</button>
				</view>
				<view class="" @click="videoPay(0, 0, 0, detailData.isPay)">{{ detailData.isPay ? '立即观看' : '立即购买' }}</view>
			</view>
		</view>

		<view class="popul" v-if="lecturer" @touchmove.stop.prevent>
			<view class="test">
				<view class="title">讲师介绍</view>
				<view class="lecturer-detail">
					<view class="left">
						<view class=""><image :src="lecturerDetail.lecturer_head" mode=""></image></view>
						<view class="left-tow">
							<view class="">老师：{{ lecturerDetail.lecturer_name }}</view>
							<view class="" v-for="item in lecturerDetail.label">{{ item }}</view>
						</view>
					</view>
					<view class="right"><image src="http://www.szzn.group/uploads/20221103/b47431cdac776ede2b5f5f6ecc2e2f56.png" mode=""></image></view>
				</view>
				<view class="content">
					<scroll-view :scroll-y="true" class="scroll-Y">
						<view>{{ lecturerDetail.explain }}</view>
						<mp-html :content="lecturerDetail.content"></mp-html>
					</scroll-view>
				</view>
				<view class="popul-foorder"><view class="" @click="comfig">确认</view></view>
			</view>
		</view>
	</view>
</template>

<script>
import { plantspecialDetail, plantSpecialCount, plantLecturer, plantCollect, planGettSpecialList, plantSectionPayOrder, planGetMaterialData } from '@/api/api.js';
export default {
	data() {
		return {
			active: 1,
			videoContext: '',
			palybtn: true,
			currentTime: '', //时长
			trysee: false,
			detailId: '',
			detailData: {},
			recordCoujnt: '',
			lecturer: false,
			lecturerDetail: '',
			content: '', //课程详情内容
			courseList: [], //视频列表,
			phone_name: '0000-1010101', //客服电话
			phone_title: '客服电话',
			shipinLink: '',
			shipintitle: '',
			falg: '',
			isPay: '', //是否购买
			trytime: '', //试看时间
			shipinFengmian: '', //封面
			fengmian: true,
			try: '', //第一条视频的试看时间
			istry: '' //第一条视频是否支持试看
		};
	},
	onShow() {
		this.videoContext = uni.createVideoContext('myVideo');
		if (uni.getStorageSync('token') == '' || uni.getStorageSync('token') == null) {
			uni.showModal({
				title: '提示',
				content: '未登入,请先登入',
				success: function(res) {
					if (res.confirm) {
						uni.navigateTo({
							url: '/page_login/index/index'
						});
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
			return;
		}
	},
	onLoad(options) {
		this.detailId = options.id;
		this.plantspecialDetail(this.detailId);
		this.plantSpecialCount();
	},
	// 分享
	onShareAppMessage() {
		return {
			title: this.detailData.special.title,
			path: 'page_plantcourse/couresdetail/couresdetail?id=' + this.detailId
		};
	},
	// 分享到朋友圈
	onShareTimeline() {
		return {
			title: this.detailData.special.title,
			path: 'page_plantcourse/couresdetail/couresdetail?id=' + this.detailId
		};
	},
	methods: {
		// 联系客服
		phone_tap: function() {
			uni.makePhoneCall({
				phoneNumber: '0000-1010101' //仅为示例
			});
		},
		// 打开讲师详情
		lecturerPopul() {
			this.lecturer = true;
			let data = `mer_id=${this.detailData.teacher.id}`;
			plantLecturer(data).then(res => {
				this.lecturerDetail = res.data.data;
			});
		},
		// 关闭讲师详情
		comfig() {
			this.lecturer = false;
		},
		// 收藏
		Cllooect(id, type) {
			if (type) {
				let data = `id=${id}`;
				plantCollect(data).then(res => {
					if (res.data.code == '200') {
						uni.showToast({
							title: '取消收藏',
							duration: 1000
						});
						this.plantspecialDetail(this.detailId);
					}
				});
			} else {
				let data = `id=${id}`;
				plantCollect(data).then(res => {
					if (res.data.code == '200') {
						uni.showToast({
							title: '收藏成功',
							duration: 1000
						});
						this.plantspecialDetail(this.detailId);
					}
				});
			}
		},
		// 详情
		plantspecialDetail(id) {
			let data = `id=${id}`;
			plantspecialDetail(data).then(res => {
				if (res.data.code == '200') {
					this.detailData = res.data.data;
					this.isPay = this.detailData.isPay;
					let data = `page=${1}&limit=${16}&special_id=${this.detailData.special.id}&source_id=${0}`;
					planGettSpecialList(data).then(res => {
						this.courseList = res.data.data.list;
						this.getShipin(this.courseList[0].id);
						this.trytime = this.courseList[0].try_time;
						this.istry = this.courseList[0].is_try;
					});
				}
			});
		},

		// 获取视频
		getShipin(id, isPay) {
			let data = {
				special_id: this.detailId,
				task_id: id
			};
			planGetMaterialData(data).then(res => {
				this.shipinFengmian = res.data.data.taskInfo.image;
				setTimeout(() => {
					this.shipinLink = res.data.data.taskInfo.link;
					this.shipintitle = res.data.data.taskInfo.title;
				}, 100);
				this.falg = true;
			});
		},

		// 选择主标题
		activeC(type) {
			this.active = type;
			if (this.active == 2) {
				let data = `page=${1}&limit=${16}&special_id=${this.detailData.special.id}&source_id=${0}`;
				planGettSpecialList(data).then(res => {
					this.courseList = res.data.data.list;
				});
			} else {
				this.plantspecialDetail(this.detailId);
			}
		},
		// 返回
		back() {
			uni.navigateBack();
		},
		// 播放
		play(falg, isPay) {
			this.trysee = false;
			this.fengmian = false;
			this.palybtn = false;
			if (falg) {
				this.videoContext.play();
			} else {
			}
		},
		// 点击播放
		playy() {
			if (this.isPay) {
				this.falg = true;
				this.play(this.falg);
			} else {
				if (this.istry != 0 && this.trytime != 0) {
					this.falg = true;
					this.play(this.falg);
				} else {
					uni.showToast({
						title: '未购买，请先购买',
						duration: 2000,
						icon:'error'
					});
				}
			}
		},
		// 监听时长
		monitorDuration(e) {
			this.currentTime = parseInt(e.detail.currentTime);
			if (this.falg) {
				if (this.isPay) {
				} else {
					if (this.currentTime >= this.trytime) {
						this.videoContext.pause();
						this.trysee = true;
					}
				}
			}
		},
		// 立即购买  dad
		videoPay(id, time, falg, ispay) {
			if (uni.getStorageSync('token') == '' || uni.getStorageSync('token') == null) {
				uni.showModal({
					title: '提示',
					content: '未登入,请先登入',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/page_login/index/index'
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				return;
			}
			this.falg = true;
			this.trytime = time;
			if (falg) {
				let data = {
					special_id: this.detailId,
					task_id: id
				};
				planGetMaterialData(data).then(res => {
					this.shipinLink = res.data.data.taskInfo.link;
					this.shipintitle = res.data.data.taskInfo.title;
					let time1 = setTimeout(() => {
						this.play(falg);
						clearTimeout(time1);
					}, 1000);
				});
				return;
			} else {
				if (time) {
					let data = {
						special_id: this.detailId,
						task_id: id
					};
					planGetMaterialData(data).then(res => {
						this.shipinLink = res.data.data.taskInfo.link;
						this.shipintitle = res.data.data.taskInfo.title;
						let time1 = setTimeout(() => {
							this.play(time);
							clearTimeout(time1);
						}, 1000);
					});
					return;
				}
			}
			if (ispay) {
				this.active = 2;
			} else {
				uni.showLoading({
					title: '加载中'
				});
				let data = {
					special_id: this.detailData.special.id,
					pay_type_num: 2,
					payType: 'weixin',
					from: 'weixin',
					pinkId: 0,
					link_pay_uid: 0
				};
				plantSectionPayOrder(data).then(res => {
					if (res.data.code == '200') {
						uni.hideLoading();
						let obj = res.data.data.result.jsConfig;
						uni.requestPayment({
							provider: 'wxpay', // 服务提提供商
							appId: obj.appid,
							timeStamp: obj.timestamp, // 时间戳
							nonceStr: obj.nonceStr, // 随机字符串
							package: obj.package,
							signType: obj.signType, // 签名算法
							paySign: obj.paySign, // 签名
							success: function(red) {
								uni.navigateBack();
							},
							fail: function(err) {
								uni.showToast({
									title: '支付失败',
									duration: 2000,
									icon:'error'
								});
							}
						});
						// }
					} else {
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon:'error'
						});
					}
				});
			}
		},
		// 浏览人数
		plantSpecialCount() {
			let data = `id=${this.detailId}`;
			plantSpecialCount(data).then(res => {
				this.recordCoujnt = res.data.data.recordCoujnt;
			});
		}
	}
};
</script>

<style lang="scss">


.video {
	position: relative;
	// 遮罩层
	.shade {
		position: absolute;
		top: 0;
		left: 0;
		width: 100vw;
		height: 500rpx;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 10;
	}
}

.back {
	position: fixed;
	top: 100rpx;
	left: 40rpx;

	image {
		width: 40rpx;
		height: 40rpx;
	}

	z-index: 100000;
}

.playbtn1 {
	image {
		width: 100rpx;
		height: 100rpx;
	}
	position: absolute;
	top: 40%;
	left: 43%;
	z-index: 1000;
}
.playbtn {
	image {
		width: 100vw;
		height: 500rpx;
	}

	position: absolute;
	top: 0;
	left: 0;
	z-index: 21;
}

.trysee {
	position: absolute;
	top: 70%;
	left: 5%;
	border-radius: 20rpx;
	background-color: rgba(0, 0, 0, 0.5);
	padding: 10rpx 20rpx;
	font-size: 28rpx;
	color: #fff;
	z-index: 21;
}

.content {
	padding: 20rpx;
	position: relative;

	.share {
		position: absolute;
		top: 60rpx;
		right: 20%;
		color: #abacab;
		text-align: center;
		font-size: 28rpx;

		button {
			position: absolute;
			top: 0;
			left: -40rpx;
			opacity: 0;
		}

		image {
			width: 40rpx;
			height: 40rpx;
			vertical-align: middle;
		}
	}

	.cllooect {
		color: #abacab;
		position: absolute;
		font-size: 28rpx;
		top: 60rpx;
		right: 8%;
		text-align: center;

		image {
			width: 40rpx;
			height: 40rpx;
			vertical-align: middle;
		}
	}

	> view:nth-child(1) {
		font-weight: 700;
		font-size: 36rpx;
	}

	> view:nth-child(2) {
		display: flex;
		padding: 25rpx 0;

		view:nth-child(1) {
			font-size: 26rpx;
			color: #2db28f;
			background-color: #d6f6ee;
			padding: 4rpx 8rpx;
		}

		view:nth-child(2) {
			margin: 0 10rpx;
			font-size: 26rpx;
			color: #ff7975;
			background-color: #ffe6e5;
			padding: 4rpx 8rpx;
		}

		view:nth-child(3) {
			font-size: 26rpx;
			color: #ff9823;
			background-color: #fff4e5;
			padding: 4rpx 8rpx;
		}
	}

	> view:nth-child(3) {
		color: #696969;
		padding: 0 0 30rpx 0;
		font-weight: 700;
		border-bottom: 1px solid #eee;
	}

	> view:nth-child(4) {
		// border-top: 1px solid #eee;
		padding: 10rpx 0 0 0;
		display: flex;
		align-items: center;
		justify-content: space-between;

		> view:nth-child(1) {
			font-size: 46rpx;
			font-weight: 700;
			color: #00a178;

			text {
				font-size: 26rpx;
			}
		}

		> view:nth-child(2) {
			font-size: 25rpx;
			color: #ccc;
		}
	}

	> view:nth-child(5) {
		margin-top: 30rpx;
		padding: 30rpx;
		border-radius: 20rpx;
		background-color: #f7faf9;
		display: flex;

		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			margin-right: 20rpx;
		}

		> view:nth-child(2) {
			> view:nth-child(2) {
				padding: 10rpx 0;
				font-size: 26rpx;
				color: #ccc;
			}
		}
	}
}

.title-list {
	display: flex;
	justify-content: space-between;
	padding: 40rpx 60rpx;
}

.title-list view {
	padding: 10rpx 0;
	margin-right: 60rpx;
	color: #9a9a9a;
}

.active-style {
	font-weight: 700;
	border-bottom: 6rpx solid #0eaeae;
	color: #000 !important;
}

.coursecatalogue {
	font-size: 30rpx;
	padding: 20rpx;

	image {
		width: 55rpx;
		height: 55rpx;
	}

	> view:nth-child(1) {
		display: flex;

		// align-items: center;
		> view:nth-child(1) {
			flex: 0.4;
		}

		> view:nth-child(2) {
			flex: 4;
			display: flex;
			align-items: center;
			justify-content: space-between;

			> view:nth-child(1) {
				> view:nth-child(1) {
					font-size: 26rpx;
				}

				> view:nth-child(2) {
					font-size: 24rpx;
					padding: 5rpx 0;
					color: #ccc;
				}
			}

			> view:nth-child(2) {
				border-radius: 50px;
				background-color: #d9f5ee;
				color: #1fa884;
				padding: 8rpx 25rpx;
			}
		}
	}
}

.fooder {
	position: fixed;
	bottom: 0;
	height: 120rpx;
	padding: 10rpx 0 0 0;
	width: 100%;
	background-color: #fff;
	border-top: 1px solid #eee;

	> view {
		padding: 0 40rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		> view:nth-child(1) {
			font-size: 24rpx;
			padding: 0 50rpx;

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}

		> view:nth-child(2) {
			padding: 25rpx 170rpx;
			border-radius: 50px;
			background-color: #289958;
			color: #fff;
		}
	}
}

.courseone {
	padding: 10rpx 20rpx;

	.acquisition {
		padding: 0 0 30rpx 0;
		font-size: 34rpx;
	}
}

.border {
	border: 1px solid #eee;
	border-radius: 20rpx;
	padding: 20rpx;
	margin-bottom: 20rpx;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	font-size: 26rpx;

	image {
		width: 40rpx;
		height: 40rpx;
		vertical-align: middle;
		margin-right: 20rpx;
	}

	.border-flex {
		display: flex;
		align-items: center;
		margin-bottom: 10rpx;

		.border-title {
			width: 250rpx;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			color: #828694;
		}
	}
}

.lecturer {
	display: flex;
	margin: 20rpx 0;
	background-color: #f7faf9;
	padding: 20rpx;
	border-radius: 20rpx;

	image {
		width: 100rpx;
		border-radius: 50%;
		height: 100rpx;
		margin-right: 20rpx;
	}

	> view:nth-child(2) {
		display: flex;
		flex-direction: column;
		justify-content: space-around;

		> view:nth-child(2) {
			font-size: 26rpx;
			color: #8b909c;
		}
	}
}

.detail {
	display: flex;
	justify-content: center;
	align-items: center;
	width: 100%;

	.cutoffrule {
		height: 2rpx;
		background-color: #eee;
		width: 250rpx;
	}

	.coursedetail {
		margin: 0 40rpx;
	}
}

.textdetail {
	margin-top: 20rpx;
	font-size: 26rpx;
	color: #6f7485;
	word-wrap: break-word;
	word-break: normal;
	// text-indent: 60rpx;
	padding: 0 0 130rpx 0;

	image {
		width: 100%;
	}
}

.examineall {
	display: flex;
	justify-content: center;
	align-content: center;

	image {
		width: 30rpx;
		height: 30rpx;
		margin-top: 5rpx;
		vertical-align: middle;
	}
}

.popul {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	height: 800rpx;
	background-color: #fff;
	// box-shadow: 0 -1px 8px 1px #eee;
	border-radius: 20rpx;
	animation: move 0.3s;
	// color: #fff;
	z-index: 10000;
	padding: 20rpx;

	.title {
		display: flex;
		justify-content: center;
		font-size: 30rpx;
	}

	.lecturer-detail {
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #f7faf9;
		border-radius: 15rpx;
		padding: 20rpx;
		font-size: 28rpx;

		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			vertical-align: middle;
			margin-right: 20rpx;
		}

		.left {
			display: flex;
		}

		.right {
			image {
				width: 30rpx;
				height: 30rpx;
				vertical-align: middle;
			}
		}

		.test {
			position: relative;
		}
	}

	.content {
		font-size: 24rpx;
		color: #aaa;
	}

	.popul-foorder {
		position: fixed;
		width: 100%;
		display: flex;
		justify-content: center;
		bottom: 20rpx;

		view {
			background-color: #07c160;
			color: #fff;
			border-radius: 50px;
			padding: 15rpx 300rpx;
		}
	}
}

.jianjie {
	width: 680rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	font-size: 26rpx;
	margin-bottom: 20rpx;
}

.kefu {
	position: relative;

	button {
		position: absolute;
		top: 0;
		left: 0;
		opacity: 0;
	}
}

.zz-price {
	font-size: 32rpx !important;
}

.zz-title {
	font-size: 34rpx !important;
}

@keyframes move {
	0% {
		height: 0;
	}

	100% {
		height: 800rpx;
	}
}
.scroll-Y {
	height: 500rpx;
}
</style>
